﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using log4net;
using log4net.Config;
using Ninject.Modules;
using Quartz;
using Topshelf;
using Topshelf.Ninject;
using Topshelf.Quartz;
using Topshelf.Quartz.Ninject;
using Dln.Handler;
using Dln.Model;
using Dln.Common;
using Dln.Common.Helper;


namespace AutoRun
{
    public class CloseProblem : IJob
    {
        private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        public void Execute(IJobExecutionContext context)
        {
            log4net.Config.XmlConfigurator.Configure();
            var dtTypeList = SqlHelper.ContextDlnOnline.From<dt_order>().Where(d => d.state == 4).ToList();
            if (dtTypeList != null && dtTypeList.Count() > 0)
            {
                foreach (var item in dtTypeList)
                {
                    var weChatUsersList =
                        SqlHelper.Context.From<WeChatUsers>().Where(d => d.CardID == item.number).ToFirst();
                    if (weChatUsersList != null)
                    {
                        Log.InfoFormat("关闭工单" + weChatUsersList.Openid + item.id.ToString());
                        MessageHelper.ProblemNotice(weChatUsersList.Openid,
                            "该工单已处理完成,请及时关闭工单",
                            item.add_time,
                            "问题报修",
                            "标题:" + item.title,
                            "http://www.healthyperson.cn/Page/AutoRun/SendProblem.aspx?Id=" + item.id + "&cardId=" +
                            item.number
                            );
                    }
                }
            }
        }
    }
}
